using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using AMStudio.Common;
using AMStudio.DelegateDispather;

namespace AMStudio.UserInterface
{
	public partial class NewWorkOrder :AWinFormShell
	{
        private ProductDB db = new Common.ProductDB();
        public NewWorkOrder()
        {
            InitializeComponent();
            foreach (string s in db.ProductNames)
            {
                this.comboBoxArticle.Items.Add(s);
            }

        }

        public override bool ActivateUI()
        {


            this.UIName = this.Name;
            base.ActivateUI();
           

            return true;
        }

        protected override void Language_RfreshTag(LanguageItem item)
        {
            base.Language_RfreshTag(item);


            if (item.RelatedControl is DevComponents.DotNetBar.PanelEx)
            {
                this.Text = item.Language[LanguageString].ToString();
                item.RelatedControl.Text = string.Empty;
            }


           


        }

        protected override void Language_InitializeControl(Control UIControl)
        {
            base.Language_InitializeControl(UIControl);


            if (UIControl is DevComponents.DotNetBar.PanelEx)
            {


                DevComponents.DotNetBar.PanelEx bar = UIControl as DevComponents.DotNetBar.PanelEx;

                LanguageItem item = LanguageDB.UIDBTags[this.UIName + "." + bar.Name] as LanguageItem;

                if ((item != null) && (item.Language[LanguageString] != null))
                {
                    this.Text = item.Language[LanguageString].ToString();
                    UIControl.Text = string.Empty;
                }

            }


            




        }


        public WorkOrderItem Item = new WorkOrderItem();
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (this.textBoxName.Text.Trim().Length <= 0)
            {
                return;
            }

            if (this.comboBoxArticle.SelectedIndex < 0)
            {
                return;
            }
            Item.Name = this.textBoxName.Text.Trim();
            Item.Product = this.comboBoxArticle.Text;
            Item.StartTime = DateTime.Now.ToString();
            Item.Endtime = DateTime.Now.ToString();
            Item.Quantity = (int)this.numericUpDownQuantity.Value;
            Item.Status = 1;
            Item.Remaining = Item.Quantity;
            Item.Privilege=0;
            Item.ProductNO = txtProductNO.Text.Trim();
            this.DialogResult = DialogResult.OK;


            //if (workOrder.FindIdByWorkorderName(this.textBoxName.Text))
            //{

            //    //MessageBox.Show("Workorder name exist!!!");
            //    MessageBox.Show(name_exist);
            //    return;
            //}

            //string comment = "";
            //if (cboComment.SelectedIndex >= 0)
            //{
            //    comment = this.cboComment.Text;
            //}
            //string workorderName = workOrder.CreateNewWorkOrderDp(this.textBoxName.Text,
            //                                comment,
            //                                workOrder.GetArticleIdByName(articleNames[this.comboBoxArticle.SelectedIndex]),
            //                                (int)WorkOrderStatus.WORKORDER_STATUS_WAITING,
            //                                (int)this.numericUpDownQuantity.Value
            //                                );
            //buttonHit = "OK";
            //this.Close();
        }

		private void buttonCancel_Click(object sender, EventArgs e)
		{
            //buttonHit = "Cancel";
			this.Close();
		}
	}
}